package hxy.scan.server.controller;

import hxy.scan.server.dao.mapper.UserMapper;
import hxy.scan.server.dao.model.UserModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
public class UserController {

    @Resource
    UserMapper userMapper;

    @GetMapping("/user-create")
    public int create(UserModel customerEntity) {

        String name = customerEntity.getName();

        if (name==null){
            return 0;
        }

        int insert = userMapper.insert(customerEntity);
        return insert;
    }


    @GetMapping("/user-list")
    public List<UserModel> list() {
        List<UserModel> customerModels = userMapper.selectList(null);

        for (UserModel customerModel:customerModels){
            String name = customerModel.getName();
            if (name.equals("张三")){
                log.info("有问题");
            }
            log.info(name);
        }


        return customerModels;
    }

    @GetMapping("/user-delete")
    public int delete( int name) {
        return userMapper.deleteById(name);
    }



    @GetMapping("/user-update")
    public int update(UserModel  customerEntity) {

        return userMapper.updateById(customerEntity);
    }
}

